package net.flowas.genericcrud.audit.config;

import javax.persistence.EntityManager;

import net.flowas.genericcrud.audit.AuditService;
import net.flowas.genericcrud.audit.impl.AuditExecuteHandler;
import net.flowas.genericcrud.audit.impl.AuditResourceImpl;
import net.flowas.genericcrud.audit.impl.AuditServiceImpl;
import net.flowas.genericcrud.service.TransactionProxy;

public class AnditConfiguration {
	private EntityManager em;
    private AuditExecuteHandler auditHandler;
    private AuditResourceImpl auditResource;
	public void init() {
		auditHandler = new AuditExecuteHandler(null);
		AuditServiceImpl auditServiceImpl = new AuditServiceImpl();
		auditServiceImpl.setEm(em);
		TransactionProxy proxy = TransactionProxy.getInstance();
	    proxy.setEntityManager(em);
	    AuditService auditService= proxy.createProxy(auditServiceImpl);
		auditHandler.setAuditService(auditService);		
		auditResource = new AuditResourceImpl();
		auditResource.setAuditService(auditService);
	}
	public AuditExecuteHandler getAuditHandler() {
		return auditHandler;
	}
	public AuditResourceImpl getAuditResource() {
		return auditResource;
	}
	public void setEm(EntityManager em) {
		this.em = em;
	}
}
